<template>
  <el-menu :default-active="this.$route.path" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
           :collapse="isCollapsed">
    <h3>{{ isCollapsed ? '后台' : '通用后台管理系统' }}</h3>
    <el-menu-item @click="clickMenu(item)" v-for="item in noChildren" :index="item.path" :key="item.path">
      <!--      对icon进行数据拼接获得-->
      <i :class="'el-icon-' + item.icon"></i>
      <span slot="title">{{ item.label }}</span>
    </el-menu-item>

    <el-submenu v-for="item in hasChildren" :key="item.label">
      <template slot="title">
        <i :class="'el-icon-'+item.icon"></i>
        <span slot="title">{{ item.label }}</span>
      </template>
      <el-menu-item-group v-for="(subItem) in item.children" :key="subItem.path">
        <el-menu-item @click="clickMenu(subItem)" :index="subItem.path">{{ subItem.label }}</el-menu-item>
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>

<script>

export default {
  name: "CommonAside",
  data() {
    return {
      // path:   不需要另加一个path，直接使用this.route.path作为:default-active的取值即可！！
      menu: [
        {
          path: '/home',
          name: 'home',
          label: '首页',
          icon: 's-home',
          url: 'Home/Home'
        },
        {
          path: '/statistics',
          name: 'statistics',
          label: '系统信息情况统计',
          icon: 's-data',
          url: 'Statistics/Statistics'
        },
        {
          path: '/studentBasicInfo',
          name: 'studentBasicInfo',
          label: '学生基本信息',
          icon: 'user',
          url: 'StudentBasicInfo/StudentBasicInfo'
        },
        {
          // path: '/studentStudyInfo',
          // name: 'studentStudyInfo',
          label: '学生学习信息',
          icon: 'reading',
          // url: "StudentStudyInfo/StudentStudyInfo"
          children: [
            {
              path: '/studentCourseInfo',
              name: 'studentCourseInfo',
              label: '课程信息',
              icon: 'reading',
              url: 'StudentCourseInfo/StudentCourseInfo'
            },
            {
              path: '/studentSelectInfo',
              name: 'studentSelectInfo',
              label: '选课信息',
              icon: 'reading',
              url: 'StudentSelectInfo/StudentSelectInfo'
            }
          ]
        },
        {
          path: '/innovativeAndPractices',
          name: 'innovativeAndPractices',
          label: '学生创新实践',
          icon: 's-opportunity',
          url: 'InnovativeAndPractices/InnovativeAndPractices'
        },
        {
          path: '/studentHonorsInfo',
          name: 'studentHonorsInfo',
          label: '学生荣誉信息',
          icon: 'collection-tag',
          url: 'StudentHonorsInfo/StudentHonorsInfo'
        },
        {
          path: '/studentDailyInfo',
          name: 'studentDailyInfo',
          label: '学生日常活动',
          icon: 'time',
          url: 'StudentDailyInfo/StudentDailyInfo'
        },
        {
          path: '/studentLogInfo',
          name: 'studentLogInfo',
          label: '学生外出信息',
          icon: 'date',
          url: 'StudentLogInfo/StudentLogInfo'
        },

        {
          path: '/CardCost',
          name: 'CardCost',
          label: '校园卡消费信息',
          icon: 'date',
          url: 'CardCost/CardCost'
        },
        // {
        //   label: '其他',
        //   icon: 'location',
        //   children: [
        //     {
        //       path: '/page1',
        //       name: 'page1',
        //       label: '页面1',
        //       icon: 'setting',
        //       url: 'Other/PageOne'
        //     },
        //     {
        //       path: '/page2',
        //       name: 'page2',
        //       label: '页面2',
        //       icon: 'setting',
        //       url: 'Other/PageTwo'
        //     }
        //   ]
        // }
      ]
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    clickMenu(item) {
      this.$router.push({
        name: item.name
      })
      console.log(this.$route.path)
    }
  },
  computed: {
    //返回处理过后的数据，和data相同但是有区别
    noChildren() {
      return this.menu.filter(item => !item.children)
    },
    hasChildren() {
      return this.menu.filter(item => item.children)
    },
    isCollapsed() {
      return this.$store.state.tab.isCollapsed  //注意书写方式！！
    }
  }
}
</script>

<style lang="less" scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}

.el-menu {
  height: 100%;
  border: none;
  background: rgba(34, 34, 34, 0.7);
  z-index: 0;

  h3 {
    text-align: center;
    line-height: 48px;
    font-size: 20px;
    font-weight: bold;
    color: wheat;
    letter-spacing: 0;
    text-shadow: 0 1px 0 #999,
    0 1px 0 #444,
    0 2px 0 #333,
    0 3px 0 #222,
    0 4px 0 #111
  }
}

</style>
